<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../../common/tagInclude.jsp"%>
<%@ taglib uri="http://java.fckeditor.net" prefix="FCK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<base href="${basePath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK href="${basePath}styleAdmin/css/portalinabox.css" type="text/css" rel="stylesheet">
<link rel="stylesheet" href="${basePath}styleAdmin/ztree/css/demo.css" type="text/css">
<link rel="stylesheet" href="${basePath}styleAdmin/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="${basePath}styleAdmin/ztree/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="${basePath}styleAdmin/ztree/js/jquery.ztree.core-3.0.js"></script>
<script type="text/javascript" src="${basePath}styleAdmin/js/Calendar/WdatePicker.js"></script>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<title>文章内容管理--新增</title>
<script type="text/javascript">
	function checkForm(){
		var errors = "" ;
		if(document.getElementById("languageId").value == "" ){
			errors += "语种不能为空<br/>" ;
		}
		if(document.getElementById("channelIds").value == "" ){
			errors += "栏目不能为空<br/>" ;
		}
		if(document.getElementById("title").value == "" ){
			errors += "标题不能为空<br/>" ;
		}
		if(document.getElementById("userId").value == "" ){
			errors += "发布者不能为空<br/>" ;
		}
		var content = FCKeditorAPI.GetInstance("content");   
		if(content.GetXHTML() == ''){
			errors += "内容不能为空<br/>" ;
		}  
		if(errors.length > 0){
			document.getElementById('errors').innerHTML = "<font color='red' size='12'>" + errors  + "</font>" ;
			return ;
		} 
		document.myform.submit();
	}
	function changeText(flag){
		if(flag == '1'){
			document.getElementById('richTextDiv').style.display = 'block' ;
			document.getElementById('simpleTextDiv').style.display = 'none' ;
		}else{
			document.getElementById('richTextDiv').style.display = 'none' ;
			document.getElementById('simpleTextDiv').style.display = 'block' ;
		}
	}
</script>
</head>
<body bottomMargin="0" leftMargin="0" rightMargin="0" topmargin="0">
<form name="myform" method="post" action="${basePath}admin/news/insert">
<%@include file="../common/navigate.jsp" %>
<input type="hidden" id="channelIds" name="channelIds" value=""/>
<table width="90%" border="0" align="center" cellPadding="0" cellSpacing="0" style="margin-top:5px;">
 <tr><td align="center" colspan="2"><div id="errors"></div></td></tr>
 <tr>
	<td vAlign="top" align="center" height="157">
		<table width="10" border="1" class="mainFunctionTable"  cellpadding="0" cellspacing="1">
        	<tr height="25" class="pLabel">
            	<td colspan="2" class="td_nwarpstyle" align="left">&nbsp;&nbsp;新增文章内容</td>
            </tr>
			<tr>
         		<td align="center" width="10%">语言种类</td>
         		<td align="left">
         			<select name="languageId" id="languageId">
         				<option value="">请选择</option>
         				<c:forEach items="${languageInfoList}" var="languageInfo">
         					<option value="${languageInfo.id}" <c:if test="${languageInfo.id == languageId}">selected</c:if>>${languageInfo.name}</option>
         				</c:forEach>
         			</select>
         			&nbsp;&nbsp;<font color='red'>*</font>
         		</td>
    		 </tr>
			 <tr>
         		<td align="center" width="10%">栏目</td>
         		<td align="left">
				<input id="channelNameSel" type="text" readonly value="" style="width:250px;"/>&nbsp;<a id="menuBtn" href="#" onclick="showMenu(); return false;">选择</a></td>
    		</tr>
            <tr>
         		<td align="center" width="10%">标题</td>
         		<td align="left"><input type="text" name="title" id="title" value="" size="80"/>&nbsp;&nbsp;<font color='red'>*</font></td>
    		</tr>
             <tr>
         		<td align="center" width="10%">Tag标签</td>
    		    <td align="left"><input type="text" name="tagWords" id="tagWords" value="" size="80" readonly="readonly" onClick="selectTagWords();"/>
    		    	&nbsp;<input type="button" onclick="selectTagWords();" value="选择TAG标签">&nbsp;&nbsp;
    		    	<input type="hidden" name="tagWordsId" id="tagWordsId" value="" size="80"/>
    		    </td>
    		</tr>   		
    		
			<tr>
         		<td align="center" width="10%">发布者</td><!-- <input type="text" name="author" id="author" value="" size="80"/> -->
         		<td align="left">
         			
         			<select id="userId" name="userId" <c:if test="${userInfoSession.roleId != adminRoleId}">disabled="disabled"</c:if>>
         				<option value="">请选择发布者</option>
         				<c:forEach items="${userInfoList}" var="userInfo">
         					<option value="${userInfo.id}" <c:if test="${userInfo.id == userInfoSession.id}">selected</c:if>>${userInfo.realName}</option>
         				</c:forEach>
         			</select>
         		</td>
    		</tr>
			<tr>
         		<td align="center" width="10%">来源</td>
         		<td align="left"><input type="text" name="from" id="from" value="" size="80"/></td>
    		</tr>
			<tr>
         		<td align="center" width="10%">发布时间</td>
         		<td align="left">
				<input type="text" name="publishTime" id="publishTime" value="${currentTime}" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate" style="width:150px"/>
				&nbsp;&nbsp;<font color='red'>*</font></td>
    		</tr>
             <tr>
              <td align="center" width="10%">设置为图片文章</td>
              	<td align="left">
					<input type="radio" name="isFouceImage" value="1"/>是&nbsp;&nbsp;
					<input type="radio" name="isFouceImage" checked="checked"  value="0"/>否&nbsp;&nbsp;
					<font color='red'>选择"是"的时候请保证文本区域里边有图片上传</font>
				</td>
            </tr>
			<tr>
         		<td align="center" width="10%">关键词<font color='red'>(SEO优化)</font></td>
         		<td align="left"><input type="text" name="keywords" id="keywords" value="" size="80"/></td>
    		</tr>
			<tr>
         		<td align="center" width="10%">描述<font color='red'>SEO优化)</font></td>
         		<td align="left"><input type="text" name="newsMeta" id="newsMeta" value="" size="80"/></td>
    		</tr>
    		<!--  默认设置不置顶，审核不通过，首页不显示，列表显示。
    		<tr>
         		<td align="center" width="10%">页面显示位置</td>
         		<td align="left">
         			首页显示:[<input type="checkbox" name="isShowInIndex" id="isShowInIndex" value="1" checked="checked"/>是&nbsp;&nbsp;
         				    <input type="checkbox" name="isShowInIndex" id="isShowInIndex" value="0"/>否]&nbsp;&nbsp;
         			列表页显示:[<input type="checkbox" name="isShowInList" id="isShowInList" value="1" checked="checked"/>是&nbsp;&nbsp;
         				      <input type="checkbox" name="isShowInList" id="isShowInList" value="0"/>否]&nbsp;&nbsp;
         			置顶显示:[<input type="checkbox" name="isTop" id="isTop" value="1"/>是&nbsp;&nbsp;
         					<input type="checkbox" name="isTop" id="isTop" value="0" checked="checked"/>否]
         		</td>
    		</tr>
    		<tr>
         		<td align="center" width="10%">审核情况</td>
         		<td align="left">
         			<input type="radio" name="isReview" id="isReview" value="1" checked="checked"/>审核通过&nbsp;&nbsp;
         			<input type="radio" name="isReview" id="isReview" value="0"/>审核未通过&nbsp;&nbsp;
         		</td>
    		</tr>
    		 -->
			<tr>
         		<td align="center" width="10%">内容</td>
				<td align="left">
					<input type="radio" value="1" name="textType" id="textType" onClick="javascript:changeText('1')" checked="checked"/>富文本编辑
					<input type="radio" value="2" name="textType" id="textType" onClick="javascript:changeText('2')"/>纯文本编辑
					<div id="simpleTextDiv" style="display:none"><textarea rows="20" cols="130" id="simpleText" name="simpleText"></textarea></div>
         			<div id="richTextDiv" style="display:block"><FCK:editor height="380" instanceName="content" value=""></FCK:editor></div>
			    </td>
    		</tr>
            <tr align="left">
              <td align="center" colspan="2">
	              <a href="javascript:checkForm();"><img src="${basePath}styleAdmin/images/button/save.gif" border=0></a>
              </td>
            </tr>
          </table>
      </td>
  </tr>
</table>
</form>
<%@page import="java.util.List,cn.com.chec.en.dao.ChannelInfoDao,cn.com.chec.en.constants.Environment,cn.com.chec.en.constants.Constants,cn.com.chec.en.model.domain.ChannelInfo,cn.com.chec.en.util.UserRight" %>
<SCRIPT LANGUAGE="JavaScript">
		<!--
		var setting = {
			view: {
				dblClickExpand: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				beforeClick: beforeClick,
				onClick: onClick
			}
		};

		var zNodes =[
		     <%
		     ChannelInfoDao cldao = new ChannelInfoDao();
		     List<String> userRightSession = (List<String>)request.getSession().getAttribute(Constants.SESSIORIGHTLIST);
		     String str = "" ;
	     	List<ChannelInfo> rootList = cldao.getSubListByParentIdLanguageId(Environment.enLanguageId,0,0,Integer.MAX_VALUE);
	     	StringBuffer sb = new StringBuffer();
	     	for(ChannelInfo info : rootList){
	     		
	     		// 把新闻及其所有子栏目内都列举出来
		    	 if(Environment.enNewsChannelId == info.getChannelId() && userRightSession.contains("3011")){
		    			sb.append(",{id:" + info.getChannelId() + ", pId:" + info.getChannelParentId() + ", name:\"" + info.getChannelName() + "\"}" + "\r\n");
		     			sb.append(cldao.printChildren(Environment.enLanguageId,Environment.enNewsChannelId,-1));
		     	}
		     		
		     	   // 把科研开发及其所有子栏目内都列举出来
		    	 if(Environment.enDevelopmentId == info.getChannelId() && userRightSession.contains("3021")){
		    			sb.append(",{id:" + info.getChannelId() + ", pId:" + info.getChannelParentId() + ", name:\"" + info.getChannelName() + "\"}" + "\r\n");
		     			sb.append(cldao.printChildren(Environment.enLanguageId,Environment.enDevelopmentId,-1));
		     	}
		     	   
		     	  // 把成功案例及其所有子栏目内都列举出来
		    	 if(Environment.enStoryChanneLId == info.getChannelId() && userRightSession.contains("3031")){ 
		    			sb.append(",{id:" + info.getChannelId() + ", pId:" + info.getChannelParentId() + ", name:\"" + info.getChannelName() + "\"}" + "\r\n");
		     			sb.append(cldao.printChildren(Environment.enLanguageId,Environment.enStoryChanneLId,-1));

		     	}
		     	   // 把joinUS及其所有子栏目内都列举出来
		    	 if(Environment.enJoinusChannelId == info.getChannelId() && userRightSession.contains("3041")){
		    			sb.append(",{id:" + info.getChannelId() + ", pId:" + info.getChannelParentId() + ", name:\"" + info.getChannelName() + "\"}" + "\r\n");
		     			sb.append(cldao.printChildren(Environment.enLanguageId,Environment.enJoinusChannelId,-1));
		     	}
		     	   
		    	//About CHEC 
		    	 if(Environment.enAboutusChannelId == info.getChannelId() && (userRightSession.contains("3051") || userRightSession.contains("3061"))){
		    		 sb.append(",{id:" + info.getChannelId() + ", pId:" + info.getChannelParentId() + ", name:\"" + info.getChannelName() + "\"}") ;
			    	 List<ChannelInfo> channelAboutCHCList = cldao.getSubListByParentIdLanguageId(Environment.enLanguageId,Environment.enAboutusChannelId,0,100);
			    	 for(ChannelInfo aboutCHCTree : channelAboutCHCList){
			    		 // 关于我们的时候，看是否有证书
			    		 if(Environment.enAboutusCertificate_and_Reputation == aboutCHCTree.getChannelId() && userRightSession.contains("3061")){
			    			 sb.append(",{id:" + aboutCHCTree.getChannelId() + ", pId:" + aboutCHCTree.getChannelParentId() + ", name:\"" + aboutCHCTree.getChannelName() + "\"}") ;
			    			 List<ChannelInfo> channelZhengshuList = cldao.getSubListByParentIdLanguageId(Environment.enLanguageId,Environment.enAboutusCertificate_and_Reputation,0,100);
					    	 for(ChannelInfo zhengshuTree : channelZhengshuList){
					    		 sb.append(",{id:" + zhengshuTree.getChannelId() + ", pId:" + zhengshuTree.getChannelParentId() + ", name:\"" + zhengshuTree.getChannelName() + "\"}") ;
					    	 }
			    		 }
			    		 else{
			    			if(userRightSession.contains("3051"))
			    				sb.append(",{id:" + aboutCHCTree.getChannelId() + ", pId:" + aboutCHCTree.getChannelParentId() + ", name:\"" + aboutCHCTree.getChannelName() + "\"}") ;
			    		 }
			    	 }
		    	 }
		     	// 六大业务
		    	 if(Environment.enBusinessChannelId == info.getChannelId() && UserRight.isCanOprBusiness(userRightSession,"1")){
		    		 sb.append(",{id:" + info.getChannelId() + ", pId:" + info.getChannelParentId() + ", name:\"" + info.getChannelName() + "\"}") ;
			    	 List<ChannelInfo> channelBusinessList = cldao.getSubListByParentIdLanguageId(Environment.enLanguageId,Environment.enBusinessChannelId,0,100);
			    	 
		    		 for(ChannelInfo channelBusinessTree : channelBusinessList){
		    			 if(Environment.enBusinessHeavyMachineryId == channelBusinessTree.getChannelId() &&  userRightSession.contains("6011")){
				    		 sb.append(",{id:" + channelBusinessTree.getChannelId() + ", pId:" + Environment.enBusinessChannelId + ", name:\"" + channelBusinessTree.getChannelName() + "\"}") ;
				    		 sb.append(cldao.printChildren(Environment.enLanguageId,Environment.enBusinessHeavyMachineryId,-1));
			    		 }
		    			 if(Environment.enBusinessEnvironmentalProtectionWaterTreatmentId == channelBusinessTree.getChannelId() && userRightSession.contains("6021")){
				    		 sb.append(",{id:" + channelBusinessTree.getChannelId() + ", pId:" + Environment.enBusinessChannelId + ", name:\"" + channelBusinessTree.getChannelName() + "\"}") ;
		    				 sb.append(cldao.printChildren(Environment.enLanguageId,Environment.enBusinessEnvironmentalProtectionWaterTreatmentId,-1));
		    			 }
		    			 if(Environment.enBusinessEPCServiceId == channelBusinessTree.getChannelId() &&  userRightSession.contains("6031")){
				    		 sb.append(",{id:" + channelBusinessTree.getChannelId() + ", pId:" + Environment.enBusinessChannelId + ", name:\"" + channelBusinessTree.getChannelName() + "\"}") ;
		    				 sb.append(cldao.printChildren(Environment.enLanguageId,Environment.enBusinessEPCServiceId,-1));
			    		 }
		    			 if(Environment.enBusinessNewEnergyTechnologyId == channelBusinessTree.getChannelId() &&  userRightSession.contains("6041")){
				    		 sb.append(",{id:" + channelBusinessTree.getChannelId() + ", pId:" + Environment.enBusinessChannelId + ", name:\"" + channelBusinessTree.getChannelName() + "\"}") ;
		    				 sb.append(cldao.printChildren(Environment.enLanguageId,Environment.enBusinessNewEnergyTechnologyId,-1));
			    		 }
		    			 if(Environment.enBusinessEnergyTechnologyResearchServiceId == channelBusinessTree.getChannelId() && userRightSession.contains("6051")){
				    		 sb.append(",{id:" + channelBusinessTree.getChannelId() + ", pId:" + Environment.enBusinessChannelId + ", name:\"" + channelBusinessTree.getChannelName() + "\"}") ;
		    				 sb.append(cldao.printChildren(Environment.enLanguageId,Environment.enBusinessEnergyTechnologyResearchServiceId,-1));
			    		 }
		    			 if(Environment.enBusinessInternationalTradeId == channelBusinessTree.getChannelId() && userRightSession.contains("6061")){
				    		 sb.append(",{id:" + channelBusinessTree.getChannelId() + ", pId:" + Environment.enBusinessChannelId + ", name:\"" + channelBusinessTree.getChannelName() + "\"}") ;
		    				 sb.append(cldao.printChildren(Environment.enLanguageId,Environment.enBusinessInternationalTradeId,-1));
			    		 }
		    		 }
		    	 }
	     	}
	     	if(org.apache.commons.lang.StringUtils.isNotBlank(sb.toString())){
     			out.print(sb.toString().substring(1));
     		}
		     %>
		 ];

		function beforeClick(treeId, treeNode) {
			var check = (treeNode && !treeNode.isParent);
			if (!check) alert("请选择最后一级栏目!");
			return check;
		}
		
		function onClick(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			nodes = zTree.getSelectedNodes(),
			v = "";
			ids = "" ;
			nodes.sort(function compare(a,b){return a.id-b.id;});
			for (var i=0, l=nodes.length; i<l; i++) {
				v += nodes[i].name + ",";
				ids += nodes[i].id + "," ;
			}
			if (v.length > 0 ) v = v.substring(0, v.length-1);
			if (ids.length > 0 ) ids = ids.substring(0, ids.length-1);
			var cityObj = $("#channelNameSel");
			cityObj.attr("value", v);
			var checkChannelId = $("#channelIds");
			checkChannelId.attr("value",ids);
		}

		function showMenu() {
			var cityObj = $("#channelNameSel");
			var cityOffset = $("#channelNameSel").offset();
			$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");

			$("body").bind("mousedown", onBodyDown);
		}
		function hideMenu() {
			$("#menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
				hideMenu();
			}
		}

		$(document).ready(function(){
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		});
		//-->
	</SCRIPT>
<div id="menuContent" class="menuContent" style="display:none; position: absolute;">
	<ul id="treeDemo" class="ztree" style="margin-top:0; width:668px;"></ul>
</div>
<script type="text/javascript">
	function selectTagWords(){
		var returnValue = showModalDialog('${basePath}tag/select?tagWords=' + document.getElementById("tagWordsId").value, '', 'dialogWidth:350px;dialogheight:420px');
		if(returnValue != null && returnValue != ''){
			var values = returnValue.split(";");
			var valuesLen = values.length;
			var tagId = "";
			var tagName = "" ;
			for(var i = 0 ;i < valuesLen ;i ++ ){
				if(values[i] != null && values[i] != ''){
					tagId += values[i].split(",")[0] + ",";
					tagName += values[i].split(",")[1] + ",";
				}
			}
			document.getElementById("tagWordsId").value = tagId;
			document.getElementById("tagWords").value = tagName;
		}
	}
</script>
</body>
</html>